//
// Created by jyh on 2021/7/30.
//

#ifndef BBOVRSCHIP_COM_H
#define BBOVRSCHIP_COM_H

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "Taiutc.h"
#include "Patterns.h"
#include "Const.h"
#include "Deploy.h"
#include "Rnxeph.h"

// Function
char *trim(char *str);
char *trim(char *str);
int len_trim(const char* pStr);
char* substringEx(char* dest, const char* src, int start, int length);
char* left_justify_string(char* string);
char* toUpper(char* value);
char* toLower(char* value);
bool isUpperLetter(unsigned char data);
extern void split_string(bool lnoempty, char* string, char c_start, char c_end, char seperator, int* nword, char* keys, int len);
int pointer_string(int cnt, char* string_array[], char* str);
int pointer_charstr(int row, int col, const char* string_array, const char* string);
int index_string(const char* src, char key);
char* Itoa(int src);

void yr2year(int *yr);
extern int md_julday(int, int, int);
void yeardoy2monthday(int iyear, int idoy, int* imonth, int* iday);
double timdif(int jd2, double sod2, int jd1, double sod1);
void mjd2wksow(int mjd, double sod, int* week, double* sow);
void mjd2doy(int jd, int* iyear, int* idoy);
void mjd2date(int jd, double sod, int* iyear, int* imonth, int* iday, int* ih, int* imin, double* sec);
time_t mjd2time(int mjd, double sod);
void time2mjd(time_t time, int* mjd, double* sod);
void wksow2mjd(int week, double sow, int* mjd, double* sod);
void gpsweek(int year, int month, int day, int* week, int* wd);
void timinc(int jd, double sec, double delt, int* jd1, double* sec1);
void brdtime(char* cprn, int* mjd, double* sod);
int genAode(char csys, int mjd, double sod, double toe, int inade, struct GPSEPH* eph);

void blhxyz(double* geod, double a0, double b0, double* x);
void xyzblh(double* x, double scale, double a0, double b0, double dx, double dy, double dz, double* geod);
void rot_enu2xyz(double lat, double lon, double(*rotmat)[3]);
void matmpy(double* A, double* B, double* C, int row, int colA, int colB) ;
void transpose(double* in, double* out, int row, int col);

void excludeAnnoValue(char* value, const char* in);

void getfreq(char csys, char* freq, int ifreq, double* val);
int index_freq(char(*cfreq)[LEN_FREQ], int nfreq, const char* freq);
void get_freq(struct Satellite* SAT, const char* type, int nfreq, char(*cfreq)[LEN_FREQ]);
double freqbytp(int isat, const char* freq);
void updateSatfreq(struct Satellite* sat);
double dot(int n, double* v1, double* v2);
double distance(int n, double* v1, double* v2);
bool exsitobs(double obs[2*MAXFREQ]);

int read_siteinfo(struct Station* SIT);
void fillobs(char* line, int nobs, int itemlen, double ver);
void filleph(char* line, double ver);

// Typedef


// Variable


#endif //BBOVRSCHIP_COM_H
